"""Example Singleton Implementation
from http://www.swc.scipy.org/lec/oop02.html
"""

class SingletonClass(object):
    "Singleton Class"
    
    # The unique Instance of the class
    instance = None
    
    # The constructor fails if an instance already exists
    def __init__(self):
        assert SingletonClass.instance is None, "Trying to create a second instance"
        SingletonClass.instance = self
        
# Make a creation function that looks like a class constructor
def Singleton():
    "Create and store the Singleton class or return an existant one"
    if SingletonClass.instance:
        return SingletonClass.instance
    return SingletonClass()

def _module_test():
    first  = Singleton()
    second = Singleton()
    print 'first  instance', id(first)
    print 'second instance', id(second)
    
    
if __name__ == '__main__':
    _module_test()